package ru.urfc.portal.model.radio;

import java.util.UUID;

import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.xml.bind.annotation.XmlTransient;

import ru.urfc.portal.model.SpectrObjectWithCheck;
import ru.urfc.portal.model.accounting.Contragent;
import ru.urfc.portal.model.catalogs.DeviceState;
import ru.urfc.portal.model.catalogs.DeviceType;

@MappedSuperclass
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
abstract public class BaseDevice extends SpectrObjectWithCheck {
	@ManyToOne
	private NetWithLicense net;
	private String guid;
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "deviceType_id")
	public DeviceType type;
	public String number;
	public int nChannels;
	public int watts;
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "deviceState_code")
	public DeviceState state;
	public String city;
	public String address;
	public String telegraphCallsign;
	public String telegraphCallsignNumber;
	public String telephoneCallsign;
	public String telephoneCallsignNumber;
	
	public BaseDevice() {
		super();
	}

	public BaseDevice(NetWithLicense net, DeviceType type, String number, int nChannels,
			int watts, DeviceState state, String city, String address, 
			String telegraphCallsign, String telegraphCallsignNumber,
			String telephoneCallsign, String telephoneCallsignNumber) {
		this.guid = UUID.randomUUID().toString();
		this.net = net;
		this.type = type;
		this.number = number;
		this.nChannels = nChannels;
		this.watts = watts;
		this.state = state;
		this.city = city;
		this.address = address;
		this.telegraphCallsign = telegraphCallsign;
		this.telegraphCallsignNumber = telegraphCallsignNumber;
		this.telephoneCallsign = telephoneCallsign;		
		this.telephoneCallsignNumber = telephoneCallsignNumber;		
	}
	
	public BaseDevice(NetWithLicense net) {
		this.net = net;
	}

	@XmlTransient
	public NetWithLicense getNet() {
		return net;
	}
	
	@XmlTransient
	public String getGuid() {
		return guid;
	}

	@Override
	public Contragent getContragent() {
		return net.getContragent();
	}
	
}
